// 2025.03.06 14:33 星期四 晴 ccccc1 不更了 可有可无 皆为 可无

import { normalizeContainer } from '../../Func';
import { keyboardevent_specialKey_check } from '../Func/keyboardEventSpecialKeyCheck';
// eslint-disable-next-line no-unused-vars
import { freeze_listenEvent_info_mana } from './Classes/cla_freeze_listenEvent_info_mana';
import { create_ListenEvent_mana } from './Classes/cla_unit_listenEvent_mana';

const win_listen_spacename_listenMana = 'listenMana';

const listen_spacename_freezeName = 'listenMana_freeze';

// 这个是 事件 管理
let static_listenEvent = create_ListenEvent_mana(
  win_listen_spacename_listenMana
);

/**
 * @type {freeze_listenEvent_info_mana}
 */
let freezeobj;

let listenEvent_id = 'listenEvent';

let listenEvent_EL;

function init_listen() {
  listenEvent_EL = normalizeContainer(listenEvent_id);

  freezeobj = static_listenEvent.freezeSpace(listen_spacename_freezeName);

  // freezeobj = static_listenEvent[listen_spacename_freezeName];

  // console.log(freezeobj);

  static_listenEvent.addEventListen(
    listenEvent_EL,
    'click',
    listenEvent_El_click_self
  );

  static_listenEvent.addEventListen(
    listenEvent_EL,
    'mouseenter',
    listenEvent_El_enter
  );

  static_listenEvent.addEventListen(window, 'keydown', doc_only_ctrl_down_self);

  static_listenEvent.addEventListen(window, 'keyup', doc_only_ctrl_up);
  // console.log(static_listenEvent);
}

/**
 * listenEvent click 事件
 * @param {MouseEvent} event
 */
function listenEvent_El_click_self(event) {
  console.log('点我', event.target);
  static_listenEvent.removeEventListen(
    listenEvent_EL,
    'click',
    listenEvent_El_click_self
  );
}

function listenEvent_El_enter() {
  console.log('移进来了');
}

function doc_only_ctrl_down_self(event) {
  console.log('control down');
  if (!keyboardevent_specialKey_check(event, 'Control')) {
    return;
  }

  freezeobj.freeze(window, 'keydown');
  freezeobj.freeze(listenEvent_EL, 'mouseenter');
}

function doc_only_ctrl_up(event) {
  console.log('control up');

  if (!keyboardevent_specialKey_check(event, 'Control')) {
    return;
  }

  freezeobj.unfreezeAll();
  // freezeobj.unfreeze(window);
  // freezeobj.unfreeze(listenEvent_EL, 'mouseenter');
}

export { init_listen };
